package com.dm.mapper;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Constants;
import com.dm.entity.Room;
import com.dm.entity.Student;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.mapping.FetchType;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author dancun
 * @since 2021-05-02
 */
@Mapper
@Repository
public interface StudentMapper extends BaseMapper<Student> {
    @Results(id = "baseMap" ,value = {
            @Result(column="rid",property="room",one=@One(select="com.dm.mapper.RoomMapper.getOneRoom",fetchType= FetchType.EAGER)),
            @Result(column="rid",property="rid")
    })

    @Select("select * from student ${ew.customSqlSegment}")
    public List<Student> listStudent(@Param(Constants.WRAPPER) QueryWrapper wrapper);

    @ResultMap(value = "baseMap")
    @Select("select * from student where scode = #{id}")
    public Student getOneStudent(Integer id);


}
